package com.liwei.app;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;

public class MyApp8 {

    LinkedList<Node> linkedList=new LinkedList<>();
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    //节点类型
    public static class Node{
        String name;
        Node parent;
    }
    public void getPath(Node node){
        Node parent = node.getParent();
        //判断传入的node有没有父亲
        if (parent!=null){
            linkedList.push(parent);
            getPath(parent);
        }
    }
    public String execute(Node node){
        //把自己入栈
        linkedList.push(node);
        //把父亲入栈
        getPath(node);
        //出栈
        StringBuffer stringBuffer = new StringBuffer();
        while (linkedList.peek() != null) {
            Node pop = linkedList.pop();
            stringBuffer.append(pop.getName());
            stringBuffer.append(File.separator);
        }
        return stringBuffer.toString();
    }

    public static void main(String[] args) {
        //创建节点
        Node nodeSrc = new Node("sre",null);

        Node nodeMain = new Node("main",nodeSrc);
        Node nodeTest = new Node("Test",nodeSrc);

        Node nodeJava = new Node("java",nodeMain);
        Node nodeResources = new Node("resources",nodeMain);

        Node nodeCom = new Node("com",nodeJava);

        Node nodeLiWei= new Node("liwei",nodeCom);

        Node nodeApp= new Node("app",nodeLiWei);

        ArrayList<Node> nodes = new ArrayList<>();
        nodes.add(nodeMain);
        nodes.add(nodeTest);
        nodes.add(nodeJava);
        nodes.add(nodeResources);
        nodes.add(nodeApp);

        MyApp8 myApp8 = new MyApp8();
        for (Node node : nodes) {
            String execute = myApp8.execute(node);
            execute="d:\\web\\"+execute;
            File file = new File(execute);
            boolean mkdirs = file.mkdirs();
            if (mkdirs){
                System.out.println(execute+"创建成功...........");
            }else {
                System.out.println(execute+"创建失败...........");
            }
        }

//        MyApp8 myApp8 = new MyApp8();
//        String execute = myApp8.execute(nodeApp);
//        System.out.println(execute);


        /*MyApp8 myApp8 = new MyApp8();
         //把自己入栈
        myApp8.linkedList.push(nodeResources);
        //把父亲入栈
        myApp8.getPath(nodeResources);
        //出栈
        StringBuffer stringBuffer = new StringBuffer();
        while (myApp8.linkedList.peek() != null) {
            Node pop = myApp8.linkedList.pop();
            stringBuffer.append(pop.getName());
            stringBuffer.append(File.separator);
        }
        System.out.println(stringBuffer.toString());*/
    }
}
